package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCommentMapper;
import com.qf.pojo.DtsComment;
import com.qf.service.DtsCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project E-commercebackGroundManagementSystem
 * @date 2022/9/24 22:30
 */
@Service
public class DtsCommentServiceImpl  implements DtsCommentService {
    @Autowired
    private DtsCommentMapper dtsCommentMapper;
    @Override
    public Page<DtsComment> selectPage(Integer limit, Integer page, String order, String sort, Integer userId, Integer valueId) {
        Page<DtsComment> dtsCommentPage = new Page<>(page,limit);
        QueryWrapper<DtsComment> dtsCommentQueryWrapper = new QueryWrapper<>();
        dtsCommentQueryWrapper.orderBy(!StringUtils.isEmpty(sort),"asc".equalsIgnoreCase(order),sort).lambda().eq(valueId!=null,DtsComment::getValueId,valueId).eq(userId!=null,DtsComment::getUserId,userId).eq(DtsComment::getDeleted,false);

        return dtsCommentMapper.selectPage(dtsCommentPage,dtsCommentQueryWrapper);
    }

    @Override
    public void insert(DtsComment dtsComment) {
         dtsCommentMapper.insert(dtsComment);
    }

    @Override
    public void delete(DtsComment dtsComment) {
        dtsCommentMapper.updateById(dtsComment);
    }
}
